<?php
/**
 * 根据trade执行BUY操作。
 * TransHistory
 */
require 'config.php';
require 'Lib_btc.php';

$user = getBtcAccount(BTC_DEFAULT_USER);
$groupOrders = getToSellOrders();
echo '<pre>';
$i=0;
if( !empty($groupOrders) )
	foreach( $groupOrders AS $pair=>$orders )
{
	foreach( $orders AS $order )
	{
		$result = btce_query("Trade",
					array("pair" => $pair,
						 	"type" => "sell",
							"amount" => $order['amount'],
							"rate" => $order['pre_sell_rate']
						)
			);
		if( $result['success'] == BTC_API_SUCCESS)
		{
			$i++;
			sellOrder( $order['order_id'],'-1' );

		}
		else
		{
			var_dump($order);
			var_dump($result);
		}
		sleep(2);
	}
}
if( $i > 0 )
	logBtcApiResult('SellOrder:'.$rule['pair'],'获取交易数量：'.$i.'个。');
echo "<script>
<!--
setTimeout(function(){location.replace(location.href);},300000);
//-->
</script>";
?>
